Fix test isolation, fast polling, and cleanup of command tests#51
Merged
Fix test isolation, fast polling, and cleanup of command tests#51
Conversation
Test Isolation: - Add `credentialsFile` parameter to ResolveConfigOptions and LoadConfigOptions - Update MobifySource to use credentialsFile when provided (overrides ~/.mobify) - Add --credentials-file flag with MRT_CREDENTIALS_FILE env var to MrtCommand - Add config-isolation.ts helper to clear SFCC_*/MRT_* env vars for tests Fast Polling Tests: - Use short pollInterval for site-archive tests instead of default 3000ms - Tests now complete in milliseconds instead of seconds Command Test Cleanup: - Delete cartridge-command.test.ts (100% trivial delegation tests) - Simplify base-command.test.ts (keep getExtraParams, catch tests) - Simplify instance-command.test.ts (keep requireX, context tests) - Simplify mrt-command.test.ts (keep requireMrtCredentials only) - Simplify oauth-command.test.ts (keep parseAuthMethods, requireOAuthCredentials) - Simplify ods-command.test.ts (keep odsClient lazy init tests) Documentation: - Update testing skill with config isolation, pollInterval patterns - Add command test guidelines (what to test vs avoid) - Remove general knowledge content (basic Mocha/Chai patterns)
52c91db to
aafef91
Compare
- Change loadDwJson() default to look only at ./dw.json (no parent search) - Update DwJsonSource to use same logic, remove findDwJson import - Keep findDwJson() exported for users who need explicit upward search - Set SFCC_CONFIG=/dev/null and MRT_CREDENTIALS_FILE=/dev/null in isolateConfig() - Update test to verify new behavior (no upward search)
Add isolateConfig()/restoreConfig() to command test files to ensure tests are isolated from developer's environment variables (SFCC_*, MRT_*). Files updated: - test/cli/base-command.test.ts - test/cli/instance-command.test.ts - test/cli/mrt-command.test.ts - test/cli/oauth-command.test.ts - test/cli/ods-command.test.ts
- Add sinon, @types/sinon, @oclif/test as SDK dev dependencies - Create stubParse helper for cleaner parse method mocking - Refactor 5 command test files to use Sinon instead of manual mocking - Add test fixture (test/fixtures/test-cli/) for integration testing - Add base-command.integration.test.ts with runCommand() tests - Update testing skill docs with new patterns The stubParse helper eliminates the brittle MockableXxxCommand type casting pattern. Integration tests exercise full command lifecycle through the oclif test utilities.
- Add cartridge-command.test.ts with tests for cartridgePath, cartridgeOptions, provider runner init, and findCartridgesWithProviders - Use stubParse helper with server mock for instance-dependent tests - Improves cartridge-command.ts coverage from 19% to 91%
Integration tests provide API contract validation beyond code coverage: - Catch flag definition errors (wrong type, missing env var) - Validate baseFlags inheritance works correctly - Exercise full oclif command lifecycle (discovery, parse, init, run) - Test commands the way consumers actually use them New fixtures: - test-instance.js: Tests server, instance flags and hasServer check - test-mrt.js: Tests api-key, project, environment, cloud-origin flags New integration tests: - instance-command.integration.test.ts (5 tests) - mrt-command.integration.test.ts (8 tests) Total integration tests: 18 (BaseCommand + InstanceCommand + MrtCommand)
charithaT07
previously approved these changes
Jan 15, 2026
Collaborator
charithaT07
left a comment
There was a problem hiding this comment.
Thank you for identifying and addressing the root causes of the test failures, this was a tricky one because the failures only surfaced for some developers due to local config files and environment variables. The new test patterns using sinon, @oclif/test, the stubParse helper, and the fixture CLI project provide a cleaner approach for testing command behavior without brittle overrides. I’ll review the other SDK test files to align them with these updated patterns and ensure consistency across the suite. Thanks again for driving this .
Resolve conflict in base-command.test.ts by: - Keeping test helper utilities (config-isolation, stub-parse) from feature branch - Adding globalMiddlewareRegistry cleanup from main - Adding extra-headers tests from main using feature branch patterns
charithaT07
approved these changes
Jan 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses three issues with the SDK test suite:
Test Isolation: Tests expecting "no credentials" were failing when developers had real
~/.mobify,dw.jsonconfig files orSFCC_*environment variables setSlow Polling Tests: Site-archive tests were slow (~3000ms each) due to default
pollIntervalinwaitForJob()Improved Command Test Patterns: Replaced brittle manual parse mocking with cleaner Sinon-based patterns and added integration tests using a test fixture
Changes
Test Isolation
credentialsFileparameter toResolveConfigOptionsandLoadConfigOptionsMobifySourceto usecredentialsFilewhen provided (overrides~/.mobify)--credentials-fileflag withMRT_CREDENTIALS_FILEenv var toMrtCommandconfig-isolation.tshelper to clearSFCC_*/MRT_*env vars for tests for general safetyFast Polling Tests
pollInterval: 10for site-archive tests instead of default 3000ms (this can probably be 0 though)Command Test Improvements
sinon,@types/sinon,@oclif/testas SDK dev dependenciesstubParsehelper for cleaner parse method mocking (replaces manual type-casted overrides)test/fixtures/test-cli/) - a mini oclif project for integration testingcartridge-command.test.tscartridgePath,cartridgeOptions, provider runner init,findCartridgesWithProvidersbase-command.test.tsgetExtraParams,catchtests onlyinstance-command.test.tsrequireX, context tests onlymrt-command.test.tsrequireMrtCredentialsonlyoauth-command.test.tsparseAuthMethods,requireOAuthCredentialsods-command.test.tsodsClientlazy init tests onlyIntegration Tests (API Contract Validation)
Integration tests validate that base commands work correctly when used the way consumers use them - catching issues that unit tests with mocked parse() cannot:
baseFlagsinheritance brokenFixture commands:
test-base.js- BaseCommand (extra-query, extra-body flags)test-instance.js- InstanceCommand (server, instance flags)test-mrt.js- MrtCommand (api-key, project, environment, cloud-origin flags)Integration tests: 18 total (5 BaseCommand + 5 InstanceCommand + 8 MrtCommand)
Documentation
pollIntervalguidanceTest plan
~/.mobifyconfigurationcartridge-command.tscoverage improved from 19% to 91%